/**
 * Copyright (C) 2015 Baidu, Inc. All Rights Reserved.
 */
package imserver.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.hibernate.Session;

import imserver.common.util.DaoException;



/**
 * @author zhanghongbin01
 * @param <T>
 *  数据库操作接口定义
 */

public interface BaseDao<T> {
    
    /**
     * 获取数据库session
     * @return
     * @throws DaoException 
     */
    public Session getSession() throws DaoException;
    
    /**
     * 保存实体bean
     * @param entity
     * @throws DaoException 
     */
    public void save(T entity) throws DaoException;
    
    /**
     * 批量保存实体bean
     * @param entitys
     */
    public void save(Collection<T> entitys);
    
    /**
     * 保存或者更新实体bean信息
     * @param entity
     * @throws DaoException 
     */
    public void saveOrUpdate(T entity) throws DaoException;
    
    /**
     * 通过主键ID删除实体
     * @param id
     */
    public void delete(Serializable id);
    
    /**
     * 传入实体bean，删除数据库中的实体bean
     * @param entity
     * @throws DaoException 
     */
    public void delete(T entity) throws DaoException;
    
    /**
     * 批量删除实体bean
     * @param entitys
     */
    public void delete(Collection<T> entitys);
    
    /**
     * 更新实体信息
     * @param entity
     */
    public void update(T entity);
    
    /**
     * 执行SQL语句
     * @param sql
     * @throws DaoException 
     */
    public void exexuteSQL(String sql) throws DaoException;
    
    /**
     * 通过ID获取商品信息
     * @param id
     * @return
     * @throws DaoException 
     */
    public T get(Serializable id) throws DaoException;
    
    /**
     * 获取一张表里的所有记录
     * @return
     * @throws DaoException 
     */
    public List<T> get() throws DaoException;
    
    /**
     * 通过ID获取多个商品信息
     * @param id
     * @return
     * @throws DaoException 
     */
    public List<T> get(String sql) throws DaoException;
    
    /**
     * 执行带参数的SQL的语句
     * @param sql
     * @param paramtes
     * @return
     * @throws DaoException 
     */
    public List<T> execute(String sql, Object[] paramtes) throws DaoException;
    
    /**
     * 执行SQL，返回唯一结果
     * @param sql
     * @param paramtes
     * @return
     * @throws DaoException 
     */
    public T executeUniq(String sql, Object[] paramtes) throws DaoException;
    
    /**
     * 从数据中列出前n条数据
     * @param maxNum
     * @return
     * @throws DaoException 
     */
    public List<T> getTop(int maxNum) throws DaoException;
}
